package com.queclink.ycm.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.queclink.ycm.common.utils.MD5Utils;
import com.queclink.ycm.entity.Report;
import com.queclink.ycm.entity.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author jim.li
 * @email jim.li@queclink.com
 * @date 2022-02-10 15:30:00
 */
@RestController
@RequestMapping()
public class MD5TestController {


    // 用于测试
    @GetMapping("/md5")
    @ResponseBody
    public ResponseBean combine(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        String userAgent = httpServletRequest.getHeader("User-Agent");
        try {
            String[] userAgentArray = userAgent.split("-");
            String MD5Encryption_Data = userAgentArray[userAgentArray.length - 1];
            String dataLong = userAgent.substring(0, userAgent.lastIndexOf("-") + 1);
            String start = MD5Utils.start(dataLong);
            if (start.equalsIgnoreCase(MD5Encryption_Data)) {
                System.out.println("ok");
                return ResponseBean.ok();
            } else {
                return ResponseBean.error("MD5加密不一致");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseBean.error("MD5加密失败");
        }
    }

}
